//
//  ViewController.swift
//  alert
//
//  Created by ap0stader on 2023/10/25.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
    
    override func didReceiveMemoryWarning() {
        // Dispose of any resources that can be recreated
    }

    @IBOutlet var theTextView: UITextView!
    
    @IBAction func DeleteByAlert(_ sender: UIButton) {
        let alertController: UIAlertController = UIAlertController(title: "警告框", message: "您确定要删除上面段落中的文字吗？", preferredStyle: UIAlertController.Style.alert)
        
        let cancelAction = UIAlertAction(title: "取消", style: .cancel)
        
        let deleteAction = UIAlertAction(title: "确定", style: .default){
            (alertAction) -> Void in
            self.theTextView.text = ""
        }
        
        alertController.addAction(cancelAction)
        
        alertController.addAction(deleteAction)
        
        self.present(alertController, animated: true, completion: nil)
    }
    
    @IBAction func DeleteByActionSheet(_ sender: UIButton) {
        let actionSheetController = UIAlertController(title: "警告框", message: "您确定要删除上面段落中的文字吗？", preferredStyle: UIAlertController.Style.actionSheet)
        
        let cancelAction = UIAlertAction(title: "取消", style: .cancel)
        
        let deleteAction = UIAlertAction(title: "确定", style: .destructive){
            (alertAction) -> Void in
            self.theTextView.text = ""
        }
        
        actionSheetController.addAction(cancelAction)
        
        actionSheetController.addAction(deleteAction)
        
        self.present(actionSheetController, animated: true, completion: nil)
    }
    
    @IBAction func recover(_ sender: UIButton) {
        theTextView.text = "Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda."
    }
}

